package com.zhilianbao.leyaogo.ui.fragment.shoppingcart;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bql.roundview.RoundTextView;
import com.bql.utils.EventManager;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.events.LeEventCode;
import com.zhilianbao.leyaogo.ui.activity.me.myorder.OrderDetailActivity;
import com.zhilianbao.leyaogo.ui.fragment.base.BaseOkHttpFragment;
import com.zhilianbao.leyaogo.utils.Utils;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * ClassName: PaySuccessFragment <br>
 * Description: 支付成功页面<br>
 * Author: Cyarie <br>
 * Created: 2016/12/2 10:41 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class PaySuccessFragment extends BaseOkHttpFragment {

    @BindView(R.id.tv_back_to_home)
    RoundTextView mTvBackToHome;
    @BindView(R.id.tv_check_order)
    RoundTextView mTvCheckOrder;
    @BindView(R.id.tv_tips)
    TextView mTvTips;
    @BindView(R.id.ll_bottom_button)
    LinearLayout mLlBottomButton;

    private long orderId;

    private int type;//0 支付  1 充值


    public static PaySuccessFragment getInstance(long orderId) {
        PaySuccessFragment paySuccessFragment = new PaySuccessFragment();
        Bundle bundle = new Bundle();
        bundle.putLong("orderId", orderId);
        paySuccessFragment.setArguments(bundle);
        return paySuccessFragment;
    }

    public static PaySuccessFragment getInstance() {
        PaySuccessFragment paySuccessFragment = new PaySuccessFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("type", 1);
        paySuccessFragment.setArguments(bundle);
        return paySuccessFragment;
    }

    @Override
    protected void initToolbarHere() {

        orderId = getArguments().getLong("orderId", 0);
        type = getArguments().getInt("type", 0);
        initToolbar(type == 0 ? getString(R.string.pay_result) : getString(R.string.recharge_result));
    }

    @Override
    protected void initViewsAndEvents(Bundle savedInstanceState) {
        mTvTips.setText(type == 0 ? getString(R.string.pay_success) : getString(R.string.recharge_success));
        mLlBottomButton.setVisibility(type == 0 ? View.VISIBLE : View.GONE);
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_pay_success;
    }

    @Override
    public boolean onBackPressedSupport() {
        mActivity.finish();
        return true;
    }

    @Override
    public void leftContainerClick() {
        mActivity.finish();
    }


    @OnClick({R.id.tv_back_to_home, R.id.tv_check_order})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_back_to_home:
                EventBus.getDefault().post(new EventManager(LeEventCode.MSG_CODE_PAY_FINISH));
                mActivity.finish();
                break;
            case R.id.tv_check_order:
                Bundle bundle = new Bundle();
                bundle.putLong("userId", Utils.getUserLoginInfo().getUserId());
                bundle.putLong("orderId", orderId);
                Utils.startActivity(mActivity, OrderDetailActivity.class, bundle);
                mActivity.finish();
                break;
        }
    }

}
